package 算法;

/**
 * Created by zzy on 2018/4/25.
 */
public class 最长公共前缀 {

    public String longestCommonPrefix(String[] strs) {
        //以第一个数为标杆
        if(strs.length<=0){
            return "";
        }
        int theLong=strs[0].length();
        for(int i=0;i<strs.length;i++){
            //
            theLong=Math.min(theLong,strs[i].length());
            for(int j=0;j<theLong;j++){
             if(strs[0].charAt(j)!=strs[i].charAt(j)){
                 theLong=j;
                 break;
             }



            }
        }

        return strs[0].substring(0,theLong);
    }
}
